package org.apache.axis2.webapp;

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.transport.http.AxisServlet;

// Referenced classes of package org.apache.axis2.webapp:
//            AdminAgent

public class AxisAdminServlet extends AxisServlet
{

    private static final long serialVersionUID = 0xa2747c8ad727b416L;
    protected transient AdminAgent agent;

    public AxisAdminServlet()
    {
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException
    {
        doGet(req, res);
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException
    {
        try
        {
            req.getSession().setAttribute("servicePath", configContext.getServicePath());
            agent.handle(req, resp);
        }
        catch(Exception e)
        {
            throw new ServletException(e);
        }
    }

    public void init(ServletConfig config)
        throws ServletException
    {
        super.init(config);
        ServletContext servletContext = config.getServletContext();
        configContext = (ConfigurationContext)servletContext.getAttribute("CONFIGURATION_CONTEXT");
        servletContext.setAttribute(getClass().getName(), this);
        agent = new AdminAgent(configContext);
        servletConfig = config;
    }

    public void init()
        throws ServletException
    {
        if(servletConfig != null)
        {
            init(servletConfig);
        }
    }
}
